package com.ruoyi.app.controller.reward;

import com.ruoyi.app.business.reward.LaborRewardBusiness;
import com.ruoyi.app.config.annotation.OperationAuth;
import com.ruoyi.app.domain.reward.LaborReward;
import com.ruoyi.app.domain.reward.LaborRewardInfo;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.reward.query.RewardQuery;
import com.ruoyi.service.user.enums.UserTypeEnum;
import java.util.Objects;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 员工奖惩管理
 *
 * @author Zane
 * @since 2025-10-26 20:20
 */
@RestController
@RequestMapping("/labor/reward")
public class LaborRewardController {

  @Resource
  private LaborRewardBusiness laborRewardBusiness;

  /**
   * 奖惩记录列表[劳务方]
   */
  @OperationAuth({UserTypeEnum.LABOR_USER})
  @PostMapping("listForLabor")
  public TableDataInfo<LaborRewardInfo> listForLabor(@Validated @RequestBody RewardQuery query) {
    CommonPageInfo<LaborRewardInfo> rewards = laborRewardBusiness.listRewardLabor(query);
    return CommonUtils.buildTableData(rewards);
  }

  /**
   * 奖惩记录列表[平台方]
   */
  @OperationAuth({UserTypeEnum.PLATFORM_USER})
  @PostMapping("listForPlatform")
  public TableDataInfo<LaborRewardInfo> listForPlatform(@Validated @RequestBody RewardQuery query) {
    CommonPageInfo<LaborRewardInfo> rewards = laborRewardBusiness.listRewardPlatform(query);
    return CommonUtils.buildTableData(rewards);
  }

  /**
   * 某个人奖惩记录列表[平台方]
   */
  @OperationAuth({UserTypeEnum.PLATFORM_USER})
  @PostMapping("listForPlatformByUser")
  public TableDataInfo<LaborRewardInfo> listForPlatformByUser(
      @Validated @RequestBody RewardQuery query) {
    if (Objects.isNull(query.getUserId())) {
      throw new ServiceException("用户ID为空");
    }
    CommonPageInfo<LaborRewardInfo> rewards = laborRewardBusiness.listRewardPlatform(query);
    return CommonUtils.buildTableData(rewards);
  }

  /**
   * 奖惩处理[平台方]
   */
  @OperationAuth({UserTypeEnum.PLATFORM_USER})
  @PostMapping("doReward")
  public APIResult<Void> doReward(@Validated @RequestBody LaborReward laborReward) {
    laborRewardBusiness.doReward(laborReward);
    return APIResult.success();
  }

}
